/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function (s) {
  const arr = [];
  const n = s.length;
  for (let i = 0; i < n; i++) {
    const temp = s[i];
    switch (temp) {
      case "{":
      case "[":
      case "(":
        arr.push(temp);
        break;
      case "]":
        arr.at(-1) === "[" ? arr.pop() : arr.push("]");
        break;
      case "}":
        arr.at(-1) === "{" ? arr.pop() : arr.push("}");
        break;
      case ")":
        arr.at(-1) === "(" ? arr.pop() : arr.push(")");
        break;
    }
  }
  return arr.length === 0 ? true : false;
};

console.log(isValid("(){}"));
